package com.recharge.time;

import com.recharge.common.util.Constant;
import com.recharge.common.util.RedisUtil;
import com.recharge.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * <h2>描述:定时任务</h2>
 * @author kui
 * @date 2020/9/12 15:37
 */
@Component
public class TimeTask {

    Logger logger = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ProviderService providerService;

    @Autowired
    private ReportProviderStatisService reportProviderStatisService;

    @Autowired
    private ReportOrderGoodsStatisService reportOrderService;

    @Autowired
    private OrderService orderService;

    @Autowired
    private ProviderApiService providerApiService;

    @Autowired
    private MerchantService merchantService;

    /*@Scheduled(cron="0/5 * * * * ? ")
    public void orderSync(){
        //logger.debug(" 调用上游回调同步");
        providerApiService.syncOrderStatus();
    }*/

    @Scheduled(cron="0 0 23 * * ?")
    public void everyDayTask() {
        //超过24小时阀值自动失效
        providerService.initThreshold();
    }

    @Async
    @Scheduled(cron="0 0 0 * * ?")
    public void reportOrderGoodsTask() {
    //每天凌晨1点 执行定时任务统计订单商品表
        logger.debug("开始统计");
        reportOrderService.taskReport();
        logger.debug("结束统计");
    }

    @Async
    @Scheduled(cron="0 0 0 * * ?")
    public void reportPrividerOrderGoodsTask() {
        //每天凌晨1点 执行定时任务统计供货单商品订单表
        logger.debug("开始统计");
        reportProviderStatisService.taskReport();
        logger.debug("结束统计");
    }

   /* @Scheduled(cron="0/15 * * * * ? ")
    public void orderMerchantCallback() {
        logger.debug(" 调用下游回调");
        merchantService.sendCallBack();
    }

    @Scheduled(cron="0/10 * * * * ? ")
    public void callBackTask() {
        //logger.debug(" 订单调用上游接口");
       orderService.orderSendProvider();
    }*/
}
